/**
 * 
 */
package com.postek.coyote.postekwifi;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import com.postek.cdf.CDFPTKAndroid;
import com.postek.coyote.postekwifi.bean.HXBean;
import com.postek.coyote.postekwifi.bean.LabelBean;

import java.util.ArrayList;

/**
 * @author yrwang
 *
 */
public class PrintHXActivity extends AppCompatActivity {
	
	private CDFPTKAndroid cdf = MainActivity.cdf;
	private ArrayList<LabelBean> labelBeans = MainActivity.labelBeans;
	
	private Button btnPrint = null;
	private Button btnCancel = null;
	
	private EditText et_HX1 = null;
	private EditText et_HX2 = null;
	private EditText et_HX3 = null;
	private EditText et_HX4 = null;
	private Spinner sp_HX5 = null;
	private Spinner sp_HX6 = null;
	private EditText et_HX7 = null;
	private Spinner sp_HX8 = null;
	private Spinner sp_HX9 = null;
	private EditText et_HXS = null;
	private EditText et_print_number=null;
	private EditText et_print_cpnumber=null;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.print_hx);
		
		btnPrint = (Button) findViewById(R.id.btn_printHX_print);
		btnCancel = (Button) findViewById(R.id.btn_printHX_cancel);
		
		et_HX1 = (EditText) findViewById(R.id.et_print_HX1);
		et_HX2 = (EditText) findViewById(R.id.et_print_HX2);
		et_HX3 = (EditText) findViewById(R.id.et_print_HX3);
		et_HX4 = (EditText) findViewById(R.id.et_print_HX4);
		sp_HX5 = (Spinner) findViewById(R.id.sp_print_HX5);
		sp_HX6 = (Spinner) findViewById(R.id.sp_print_HX6);
		et_HX7 = (EditText) findViewById(R.id.et_print_HX7);
		sp_HX8 = (Spinner) findViewById(R.id.sp_print_HX8);
		sp_HX9 = (Spinner) findViewById(R.id.sp_print_HX9);
		et_HXS = (EditText) findViewById(R.id.et_print_HXS);
		et_print_number= (EditText) findViewById(R.id.et_print_number);
		et_print_cpnumber= (EditText) findViewById(R.id.et_print_cpnumber);

		btnCancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
		btnPrint.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int iHX1 = 0;
				int iHX2 = 0;
				int iHX3 = 0;
				int iHX4 = 0;
				int iHX5 = sp_HX5.getSelectedItemPosition();
				int iHX6 = sp_HX6.getSelectedItemPosition();
				int iHX7 = 0;
				int iHX8 = sp_HX8.getSelectedItemPosition();
				int iHX9 = sp_HX9.getSelectedItemPosition();
				String iHXS = et_HXS.getText().toString();

				int number=Integer.parseInt(et_print_number.getText().toString());
				int cpnumber=Integer.parseInt(et_print_cpnumber.getText().toString());
				
				if(!("".equals(et_HX1.getText().toString()))){
					iHX1 = Integer.parseInt(et_HX1.getText().toString());
				}
				
				if(!("".equals(et_HX2.getText().toString()))){
					iHX2 = Integer.parseInt(et_HX2.getText().toString());
				}
				
				if(!("".equals(et_HX3.getText().toString()))){
					iHX3 = Integer.parseInt(et_HX3.getText().toString());
				}
				
				if(!("".equals(et_HX4.getText().toString()))){
					iHX4 = Integer.parseInt(et_HX4.getText().toString());
				}
				
				if(!("".equals(et_HX7.getText().toString()))){
					iHX7 = Integer.parseInt(et_HX7.getText().toString());
				}
				
				int nReturn = cdf.PTK_DrawBar2D_HANXIN(iHX1, iHX2, iHX3, iHX4, iHX5, iHX6, iHX7, iHX8, iHX9, iHXS);
				
				if (nReturn == 0) {
					HXBean bean = new HXBean(iHX1, iHX2, iHX3, iHX4, iHX5, iHX6, iHX7, iHX8, iHX9, iHXS);
					labelBeans.add(bean);
					Toast.makeText(PrintHXActivity.this,  R.string.setting_success, Toast.LENGTH_SHORT).show();
					cdf.PTK_PrintLabel(number,cpnumber);
				} else {
					Toast.makeText(PrintHXActivity.this,  R.string.setting_fail, Toast.LENGTH_SHORT).show();
				}
			}
		});
	}
}
